package com.icoolkj.learn.juc.future;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/03/05 14:34
 */
@Slf4j
public class CFDemo3 {

    public static void main(String[] args) {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            int result = 100;
            log.info("{} 一阶段:{}", Thread.currentThread().getName(),result);
            return result;
        }).thenApply(number -> {
            int result = number * 2;
            log.info("{} 二阶段：{}", Thread.currentThread().getName(),result);
            return result;
        }).thenApply(number -> {
            int result = number * 3;
            log.info("{} 三阶段：{}", Thread.currentThread().getName(),result);
            return result;
        });

        try {
            log.info("最终结果：{}", future.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
